<template>
  <div class="wrap">
    <!-- 顶部结构 -->
    <div class="top">
      <div class="hosname">{{ hospitalWorkData.baseMap?.hosname }}</div>
      <div class="line"></div>
      <div>{{ hospitalWorkData.baseMap?.bigname }}</div>
      <div class="dot">.</div>
      <div class="hosdeparment">{{ hospitalWorkData.baseMap?.depname }}</div>
    </div>
    <!-- 中间展示日期的结构 -->
    <div class="center">
      <h1 class="time">{{ hospitalWorkData.baseMap?.workDateString }}</h1>
      <div class="container">
        <div class="item"
          :class="{ active: item.status == -1 || item.availableNumber == -1, cur: item.workDate == workTime.workDate }"
          v-for="(item, index) in hospitalWorkData.bookingScheduleList" :key="index" @click="changeTime(item)">
          <div class="top1">{{ item.workDate }}-{{ item.dayOfWeek }}</div>
          <div class="bottom">
            <div v-if="item.status == -1">停止挂号</div>
            <div v-if="item.status == 0">
              {{ item.availableNumber == -1 ? '约满了' : `有号(${item.availableNumber})` }}
            </div>
            <div v-if="item.status == 1">即将放号</div>
          </div>
        </div>
      </div>
      <!-- eslint-disable vue/no-v-model-argument -->
      <el-pagination v-model:current-page="pageNO" layout="prev, pager, next" :total="hospitalWorkData.total"
        @current-change="fetchHospitalWorkData" />
      <!-- eslint-enable vue/no-v-model-argument -->
    </div>
    <!-- 底部展示医生的结构 -->
    <div class="bottom">
      <!-- 展示即将放号的时间 -->
      <div class="will" v-if="workTime.status == 1">
        <span class="time">2023年6月3日08:30</span>
        <span class="willText">放号</span>
      </div>
      <!-- 展示医生的结构 -->
      <div class="doctor" v-else>
        <!-- 上午 -->
        <div class="morning">
          <!-- 顶部文字提示 -->
          <div class="tip">
            <svg t="1739682043441" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"
              p-id="5507" width="16" height="16">
              <path
                d="M512.001 64C264.594 64 64 264.594 64 512.001 64 759.41 264.594 960 512.001 960 759.41 960 960 759.41 960 512.001 960 264.594 759.41 64 512.001 64z m210.446 318.193l23.521 24.078-75.6 73.698-23.522-24.083 75.601-73.693z m-224.53-81.449h33.712v105.618h-33.712V300.744z m-199.388 72.487l80.079 81.873-26.545 25.985-80.079-81.87 26.545-25.988z m8.514 260.402h-114.58v-37.186h114.463v32.484h0.117v4.702z m361.759 5.601H350.72c-1.233-7.84-1.79-15.904-1.79-24.193 0-88.593 72.238-160.943 160.831-160.943 88.703 0 160.946 72.239 160.946 160.943 0 8.178-0.672 16.241-1.905 24.193z m43.484-5.176v-37.292h121.633v37.292H712.286z"
                fill="#FFB454" p-id="5508"></path>
            </svg>
            <span class="text">上午号源</span>
          </div>
          <!-- 每个医生的信息 -->
          <div class="doc_info" v-for="doctor in morningArr" :key="doctor.id">
            <div class="left">
              <div class="info">
                <span>{{ doctor.title }}</span>
                <span>|</span>
                <span>{{ doctor.docname }}</span>
              </div>
              <div class="skill">{{ doctor.skill }}</div>
            </div>
            <div class="right">
              <div class="money">${{ doctor.amount }}</div>
              <el-button type="primary" size="default" @click="goStep2(doctor)">{{ doctor.availableNumber }}</el-button>
            </div>
          </div>
        </div>
        <!-- 下午 -->
        <div class="morning">
          <!-- 顶部文字提示 -->
          <div class="tip">
            <svg t="1739684445856" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"
              p-id="6806" width="16" height="16">
              <path d="M512 512m-512 0a512 512 0 1 0 1024 0 512 512 0 1 0-1024 0Z" fill="#FF9C00" p-id="6807"></path>
              <path
                d="M281.6 281.6a20.573091 20.573091 0 0 1 28.997818 0.186182l42.821818 42.868363c7.912727 8.005818 8.052364 20.852364 0.186182 28.951273a20.573091 20.573091 0 0 1-28.997818-0.186182l-42.821818-42.821818a20.666182 20.666182 0 0 1-0.186182-28.997818zM186.181818 512c0-11.264 9.402182-20.386909 20.573091-20.386909h60.602182c11.403636 0 20.666182 9.495273 20.666182 20.386909a20.573091 20.573091 0 0 1-20.619637 20.386909H206.801455A20.712727 20.712727 0 0 1 186.181818 512z m95.418182 230.4a20.573091 20.573091 0 0 1 0.186182-28.997818l42.868363-42.821818a20.712727 20.712727 0 0 1 28.951273-0.186182 20.573091 20.573091 0 0 1-0.186182 28.997818l-42.821818 42.821818a20.712727 20.712727 0 0 1-28.997818 0.186182zM512 837.818182a20.573091 20.573091 0 0 1-20.386909-20.573091v-60.602182c0-11.403636 9.495273-20.666182 20.386909-20.666182 11.264 0 20.386909 9.402182 20.386909 20.619637v60.602181A20.712727 20.712727 0 0 1 512 837.818182z m230.4-95.418182a20.573091 20.573091 0 0 1-28.997818-0.186182l-42.821818-42.868363a20.712727 20.712727 0 0 1-0.186182-28.951273 20.573091 20.573091 0 0 1 28.997818 0.186182l42.821818 42.821818c7.912727 8.005818 8.005818 20.945455 0.186182 28.997818zM837.818182 512a20.573091 20.573091 0 0 1-20.573091 20.386909h-60.602182a20.712727 20.712727 0 0 1-20.666182-20.386909c0-11.264 9.402182-20.386909 20.619637-20.386909h60.602181c11.403636 0 20.619636 9.495273 20.619637 20.386909z m-95.418182-230.4a20.573091 20.573091 0 0 1-0.186182 28.997818l-42.868363 42.821818a20.666182 20.666182 0 0 1-28.951273 0.186182 20.573091 20.573091 0 0 1 0.186182-28.997818l42.821818-42.821818a20.712727 20.712727 0 0 1 28.997818-0.186182z m-250.740364-74.845091c0-11.357091 9.402182-20.573091 20.340364-20.573091 11.264 0 20.386909 9.402182 20.386909 20.573091v60.602182a20.712727 20.712727 0 0 1-20.386909 20.666182 20.573091 20.573091 0 0 1-20.386909-20.619637V206.754909zM318.464 512A193.629091 193.629091 0 0 1 512 318.510545 193.629091 193.629091 0 0 1 705.489455 512 193.629091 193.629091 0 0 1 512 705.489455 193.629091 193.629091 0 0 1 318.510545 512zM512 359.237818A152.901818 152.901818 0 0 0 359.237818 512 152.901818 152.901818 0 0 0 512 664.762182 152.901818 152.901818 0 0 0 664.762182 512 152.901818 152.901818 0 0 0 512 359.237818z"
                fill="#FFFFFF" p-id="6808"></path>
            </svg>
            <span class="text">下午号源</span>
          </div>
          <!-- 每个医生的信息 -->
          <div class="doc_info" v-for="doctor in afternoonArr" :key="doctor.id">
            <div class="left">
              <div class="info">
                <span>{{ doctor.title }}</span>
                <span>|</span>
                <span>{{ doctor.docname }}</span>
              </div>
              <div class="skill">{{ doctor.skill }}</div>
            </div>
            <div class="right">
              <div class="money">${{ doctor.amount }}</div>
              <el-button type="primary" size="default" @click="goStep2(doctor)">{{ doctor.availableNumber }}</el-button>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
//引入组合式API
import { onMounted, ref, computed } from 'vue';
//引入路由 路由器
import { useRoute, useRouter } from 'vue-router';
//引入api中的请求方法和ts类型
//@ts-ignore
import { reqHospitalWork, reqHospitalDoctor } from '@/api/hospital';
//@ts-ignore
import type { HospitalWorkResponseData, HospitalWorkData, DoctorResponseData, WorkData, DocArr, Doctor } from '@/api/hospital/type'


//分页器当前页码
let pageNO = ref<number>(1)
//一页几条数据
let limit = ref<number>(6)
//路由 路由器
let $route = useRoute()
let $router = useRouter()
//医院科室挂号数据
let hospitalWorkData = ref<HospitalWorkData>({} as HospitalWorkData)
//当前日期数据（挂载后拿到第一天的日期数据，点击某个日期拿到该日期数据）
let workTime = ref<WorkData>({} as WorkData)
//排班医生的数据
let docArr = ref<DocArr>([] as DocArr)

//计算属性：计算出上午/下午排班医生的数据
let morningArr = computed(() => {
  return docArr.value.filter((doctor: Doctor) => {
    return doctor.workTime == 0
  })
})
let afternoonArr = computed(() => {
  return docArr.value.filter((doctor: Doctor) => {
    return doctor.workTime == 1
  })
})

//发送请求，获取数据
const fetchHospitalWorkData = async () => {
  //发送请求
  let result: HospitalWorkResponseData = await reqHospitalWork(pageNO.value, limit.value, $route.query.hoscode as string, $route.query.depcode as string)
  if (result.code == 200) {
    //获取医院科室挂号数据
    hospitalWorkData.value = result.data
    //获取第一天日期数据
    workTime.value = hospitalWorkData.value.bookingScheduleList[0]
    //发送请求，获取数据
    getHospitalDoctorData()
  }
}
//发送请求，获取数据
const getHospitalDoctorData = async () => {
  //发送请求
  let result: DoctorResponseData = await reqHospitalDoctor($route.query.hoscode as string, $route.query.depcode as string, workTime.value.workDate)
  if (result.code = 200) {
    //获取排班医生数据
    docArr.value = result.data
  }
}
//组件挂载完毕：发送请求，获取数据
onMounted(() => {
  fetchHospitalWorkData()
})
//点击顶部某一天时候触发回调
const changeTime = (item: WorkData) => {
  //获取点击那一天的日期数据
  workTime.value = item
  //发送请求，获取数据
  getHospitalDoctorData()
}
//点击剩余号数的回调：跳转到register_step2
const goStep2 = (doctor: Doctor) => {
  $router.push({
    path: '/hospital/register_step1',
    query: {
      docId: doctor.id
    }
  })
}
</script>

<style scoped lang="scss">
.wrap {
  .top {
    display: flex;
    color: #7f7f7f;

    .line {
      width: 2px;
      height: 18px;
      background-color: #7f7f7f;
      margin: 0px 5px;
    }

    .dot {
      color: #7f7f7f;
      margin: 0px 10px;
    }
  }

  .center {
    margin: 30px 0;
    display: flex;
    flex-direction: column;
    align-items: center;

    .time {
      color: #7f7f7f;
      font-weight: 900;
    }

    .container {
      display: flex;
      width: 100%;
      margin: 30px 0;

      .item {
        flex: 1;
        width: 100%;
        border: 1px solid skyblue;
        margin: 0 5px;
        transition: all 0.5s;

        &.active {
          border: 1px solid #ccc;
          color: #7f7f7f;

          .top1 {
            background: #ccc;
          }
        }

        &.cur {
          transform: scale(1.1);
        }

        .top1 {
          height: 30px;
          width: 100%;
          background: #e8f2ff;
          text-align: center;
          line-height: 30px;
        }

        .bottom {
          height: 60px;
          width: 100%;
          text-align: center;
          line-height: 60px;
        }
      }
    }
  }

  .bottom {

    .will {
      text-align: center;
      font-size: 30px;
      font-weight: 900;

      .time {
        color: red;
      }

      .willText {
        color: skyblue;
      }
    }

    .doctor {
      .morning {
        .tip {
          display: flex;
          align-items: center;

          .text {
            color: #7f7f7f;
            font-weight: 900;
            margin-left: 5px;
          }
        }

        .doc_info {
          display: flex;
          justify-content: space-between;
          margin: 10px 0;
          border-bottom: 1px solid #ccc;

          .left {
            .info {
              color: black;
              margin: 10px 0;

              span {
                margin: 0 5px;
                font-size: 18px;
                font-weight: 900;
              }
            }

            .skill {
              margin: 10px 0;
              color: #7f7f7f;
            }
          }

          .right {
            width: 120px;
            display: flex;
            justify-content: space-between;
            align-items: center;

            .money {
              color: #7f7f7f;
              font-weight: 900;
            }
          }
        }
      }
    }
  }
}
</style>